<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../../assert/css/bootstrap.min.css" th:href="@{/assert/css/bootstrap.min.css}"/>
    <link href="../../assert/css/plugin/toastr/toastr.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/toastr/toastr.min.css}">
    <link rel="stylesheet" href="../../assert/css/animate.min.css" th:href="@{/assert/css/animate.min.css}">
    <link href="../../assert/css/loaders.css" rel="stylesheet"
          th:href="@{/assert/css/loaders.css}">
    <link rel="stylesheet" href="../../assert/css/index.css" th:href="@{/assert/css/index.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}">
    <link rel="stylesheet" href="../../assert/css/subpagesCss/main.css" th:href="@{/assert/css/subpagesCss/main.css(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}">
</head>
<body style="overflow: auto" class="scrollbar">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="main_box row">
            <div class="col-md-3">
                <div class="ibox-title left_head">
                    <img src="../../assert/image/userName.png" alt="" width="48">
                    <div class="userName">登录名： <span id="userName"></span></div>
                </div>
                <div class="ibox-title">
                    基本信息
                </div>
                <div class="left_body ibox-content fullHeight">
                    <ul>
                        <li><label>姓名：</label><span id="name"></span></li>
                        <li><label>工号：</label><span id="seatId"></span></li>
                        <li><label>角色：</label><span id="role"></span></li>
                        <li><label>班组：</label><span id="seatGroup"></span></li>
                        <li><label>手机号：</label><span id="phone"></span></li>
                    </ul>
                </div>
            </div>
            <div class="col-md-9 main_right">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="ibox-title" style="overflow: hidden;">
                            <div class="num_box" id="taskNum">
                                <!--<div><img src="../../assert/image/main_task.png" alt="" width="48"></div>-->
                                <div>待办任务<span>0</span>个</div>
                            </div>
                            <div class="num_box" id="meNum">
                                <!--<div><img src="../../assert/image/main_me.png" alt="" width="48"></div>-->
                                <div>我的考核<span>0</span>个</div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="row" id="">
                    <div class="col-sm-12">
                        <div class="ibox-title tabTitle">
                            <span class="on">待办任务</span>
                            <span>我的考核</span>
                        </div>
                        <div class="ibox-content fullHeight tab tab0" id="taskBox">
                            <ul class="table_head">
                                <li>质检任务名称</li>
                                <li>质检任务类型</li>
                                <li>待处理数量</li>
                                <li>过期日期</li>
                            </ul>
                        </div>
                        <div class="ibox-content fullHeight tab tab1" id="meBox" style="display: none">
                            <ul class="table_head">
                                <li>质检任务名称</li>
                                <li>考核月份</li>
                                <li>得分</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="main" style="display: none;"><img th:src="@{/assert/image/main.png}" alt="" width="500px"></div>
    </div>
</div>
<a href="" class="J_menuItem J_menuItem1" target="_blank" title="查看详情" data-href="/rest/page/myWork" data-index="111"
   data-txt="我的考核"></a>
<a href="" class="J_menuItem J_menuItem0" target="_blank" title="查看详情" data-href="/rest/page/agencyTask" data-index="001"
   data-txt="待办任务"></a>
<form action="" id="formDetail" class="hidden" target="_blank">
    <input type="text" id="workId" name="workId">
</form>
<a id="basePath" th:href="@{/}"></a>
</body>
<script src="../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/bootstrap.min.js" th:src="@{/assert/js/bootstrap.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/plugin/toastr/toastr.min.js" th:src="@{/assert/js/plugin/toastr/toastr.min.js}"></script>
<script src="../../assert/js/changeTime.js" th:src="@{/assert/js/changeTime.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/common.js" th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/contabs.min.js" th:src="@{/assert/js/contabs.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script>
    //项目名称
    var basePath = $("#basePath").attr("href");
    var userIdentity=$("#userIdentity",parent.document).text();//用来区分用户角色
    if(!(userIdentity=="0"||userIdentity=="1")){//如果既不是坐席也不是质检员 则看不到待办任务 我的考核的统计
        $(".main_box").hide();
        $(".main").show();
    }
    if(userIdentity=="1"){//如果是质检员 则看不到我的考核统计
        $(".tabTitle span").eq(1).hide();
        $("#meNum").hide();
        $("#taskBox li:last").html("复检剩余天数");
    }else  if(userIdentity=="0"){
        $("#taskBox li:last").html("申诉剩余天数");
    }
    //样式自适应
    var resize = {
        init: function () {
            resize.me();
            $(window).resize(function () {
                resize.me();
            })
        },
        me: function () {
            var winW = $(window).width();
            var winH = $(window).height();
            $(".ibox").width(winW - 20);
            $(".ibox").height(winH - 20 - 5);
            $(".fullHeight").css({"minHeight": (winH - 90 - 200) + "px"});
            $(".main_right .fullHeight").css({"minHeight": (winH - 30 - 200) + "px"});
        }
    };
    var getData = {
        loadElem: "",
        init: function () {
            getData.loadElem = '<div class="loaded">' +
                '<div class="loader">' +
                '<div class="loader-inner line-scale-pulse-out">' +
                '<div></div>' +
                '<div></div>' +
                '<div></div>' +
                '<div></div>' +
                '<div></div>' +
                '</div>' +
                '</div>' +
                '</div>';
            this.task();
            this.mywork();
            this.tab();
            this.jump();
            this.getUser();
        },
        task: function () {
            $("#taskBox").append(getData.loadElem);
            $.ajax({
                type: "post",
                url: basePath + "/rest/home/get-title",
                dataType: "json",
                success: function (data) {
                    $("#taskBox").find(".loaded").remove();
                    if (data.code == 0) {
                        var res = data.data;
                        if (res.length > 0) {
                            $("#taskBox .table_body").remove();
                            var numTotal = 0;
                            for (var i = 0; i < res.length; i++) {
                                var id = res[i].workId;
                                var workName = res[i].workName;
                                var workNum = res[i].workNum;
                                var daysRemaining  = res[i].daysRemaining;
                                var workType = res[i].workType;
                                var str = "";
                                numTotal += workNum;
                                if (workType == 0) {
                                    str = "自动质检"
                                } else if (workType == 1) {
                                    str = "专项质检"
                                }
                                var ul = '  <ul class="table_body" data-id="' + id + '">' +
                                    '<li title="'+workName+'">' + workName + '</li>' +
                                    '<li title="'+str+'">' + str + '</li>' +
                                    '<li class="green" title="'+workNum+'">' + workNum + '</li>' +
                                    '<li>' + daysRemaining + '</li>' +
                                    '</ul>';
                                $("#taskBox").append(ul);
                            }
                            $("#taskNum").find("span").text(numTotal);
                        }
                    }
                }
            })
        },
        mywork: function () {
            $("#meBox").append(getData.loadElem);
            $.ajax({
                type: "post",
                url: basePath + "/rest/home/get--my-ass-data",
                dataType: "json",
                success: function (data) {
                    $("#meBox").find(".loaded").remove();
                    if (data.code == 0) {
                        var res = data.data;
                        if (res.length > 0) {
                            $("#meBox .table_body").remove();
                            var numTotal = 0;
                            var arr = [];
                            for (var i = 0; i < res.length; i++) {
                                arr.push(JSON.parse(res[i]));
                            }
                            for (var i = 0; i < arr.length; i++) {
                                var id = arr[i].workId;
                                var workName = arr[i].workName;
                                var workNum = arr[i].workScore;
                                var workTime = arr[i].monthlyAssess;
                                var workType = arr[i].workType;
                                var str = "";
                                numTotal += workNum;
                                if (workType == 0) {
                                    str = "自动质检"
                                } else if (workType == 1) {
                                    str = "专项质检"
                                }
                                if(workTime==0 || workTime==null || workTime == undefined){
                                    workTime="--"
                                }
                                var ul = '<ul class="table_body" data-id="' + id + '">' +
                                    '<li title="'+workName+'">' + workName + '</li>' +
                                    '<li title="'+workTime+'">' + workTime + '</li>' +
                                    '<li class="green" title="'+workNum+'">' + workNum + '</li>' +
                                    '</ul>';
                                $("#meBox").append(ul);
                            }
                            $("#meNum").find("span").text(res.length);
                        }
                    }
                }
            })
        },
        tab: function () {
            $(".tabTitle span").on("click", function () {
                var index = $(this).index();
                $(this).addClass("on").siblings("span").removeClass("on");
                $(".tab").hide();
                $(".tab" + index).show();
            })
        },
        jump: function () {
            $(".tab1").on("click", ".table_body", function () {
                $(".J_menuItem1").attr("href", basePath + "/rest/page/myWork?workId=" + $(this).attr("data-id")).click();
                getData.defaultSelection("11",workId);
            });
            $(".tab0").on("click", ".table_body", function () {
                $(".J_menuItem0").attr("href", basePath + "/rest/page/agencyTask?workId=" + $(this).attr("data-id")).click();
                getData.defaultSelection("01",workId);
            })
        },
        defaultSelection:function(index,workId){
            var tabOnElem= $(".J_menuItem[data-index='"+index+"']",window.parent.document);
            if(!tabOnElem.parents(".layui-nav-item").hasClass("layui-nav-itemed")){
                tabOnElem.parents(".layui-nav-item").addClass("layui-nav-itemed");
            }
            $(".layui-this",window.parent.document).removeClass("layui-this");
            tabOnElem.parent().addClass("layui-this");
            tabOnElem.click();
            $(".J_menuTab[data-index='"+index+"']").click();
//            parent.menuMain.renderDot(workId);
        },
        getUser: function () {
            var url = basePath + "/rest/users/passwordSale";
            $.ajax({
                url: url,
                type: "post",
                success: function (msg) {
                    var data = msg.data;
                    $("#userName").html(data.userName).attr("data-id", data.id);
                    getData.getUserAll();
                }
            });
        },
        getUserAll: function () {
            var url = basePath + "/rest/users/getUserByPK";
            var data = {
                id: $("#userName").attr("data-id")
            };
            $.ajax({
                url: url,
                data: data,
                type: "post",
                success: function (msg) {
                    if (msg.group) {
                        var name = msg.group.name;
                        $("#seatGroup").html(name);
                    }
                    var account = msg.account;//工号
                    var realName = msg.realname;//真实姓名
                    var mobileno = msg.mobileno;
                    var roleList=msg.rolelist;
                    var roleStr="";
                    if(roleList.length>0){
                        for(var i=0;i<roleList.length;i++){
                            if(roleList[i].name){
                                roleStr+=roleList[i].name+","
                            }
                        }
                        roleStr=roleStr.substr(0,roleStr.length-1);
                    }
                    $("#name").html(realName);
                    $("#seatId").html(account);
                    $("#role").html(roleStr);
                    $("#phone").html(mobileno);
                }
            });
        }
    };
    $(function () {
        resize.init();
        getData.init();
    })
</script>
</html>

